package com.example.dao.impl;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.UUID;

import javax.jws.soap.SOAPBinding.Use;

import com.example.dao2.UserDao;
import com.example.entity.User;
import com.example.utils.DButil;
import com.mysql.jdbc.PreparedStatement;
/**
 * User表Dao层的实现类 
 * @author Roy
 *
 */
public class UserDaoImpl  implements UserDao{
 
	public User login(String username, String password) {
		String sql="select id,username,password from UserTbl where username=? and password=?";
		DButil dbUtil=new DButil();
	   Connection connect=	dbUtil.openConnection();
		try {
			java.sql.PreparedStatement pstmt=connect.prepareStatement(sql);
			pstmt.setString(1, username);
			pstmt.setString(2,password);
			ResultSet rs=pstmt.executeQuery();
			if (rs.next()) {
				//获得编号
				String id=rs.getString(1);
				User user=new User();
				user.setId(id);
				user.setPassword(password);
				user .setUsername(username);
				return user;	
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			dbUtil.closeConn(connect);
		 }
		// TODO Auto-generated method stub
		return null;
	}
	public static void main(String[] args) {
	                          User u=	new UserDaoImpl().login("admin", "123");
	                          System.out.println(u.getId());
	}

}
